package garage

import (
	"fmt"

	"github.com/labstack/echo/v4"

	"beesoft.ink/application/garage/app/helper"
	garageModel "beesoft.ink/application/garage/app/model/garage"
	"beesoft.ink/application/garage/app/service/garage"
)

var WarehouseEntry warehouseEntry

type warehouseEntry struct{}

func (r warehouseEntry) List(ctx echo.Context) error {
	var req garageModel.WarehouseEntryListReq
	err := ctx.Bind(&req)
	if err != nil {
		panic(err)
	}
	helper.SetDefaults(&req)

	res := garage.WarehouseEntry.List(ctx, &req)
	return helper.NewResponse(ctx).ResponseOk(res)
}
func (r warehouseEntry) Show(ctx echo.Context) error {
	item, err := garage.WarehouseEntry.Show(ctx)
	if err != nil {
		fmt.Println(err)
		//panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk(item)
}
func (r warehouseEntry) Store(ctx echo.Context) error {
	id, err := garage.WarehouseEntry.Store(ctx)
	if err != nil {
		panic(err)
	}
	return helper.NewResponse(ctx).ResponseCreated(echo.Map{
		"id": id,
	})
}
func (r warehouseEntry) Update(ctx echo.Context) error {
	err := garage.WarehouseEntry.Update(ctx)
	if err != nil {
		panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk()
}
func (r warehouseEntry) Destroy(ctx echo.Context) error {
	id, err := helper.ParseUintParam(ctx, "id")
	if err != nil {
		panic(err)
	}

	err = garage.WarehouseEntry.Destroy(ctx, id)
	if err != nil {
		ctx.Logger().Info("WarehouseEntry Destroy error: %+v", err)
	}

	return helper.NewResponse(ctx).ResponseOk()
}
